package com.wandian.util;

import java.util.Random;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 随机数根据类
 * 
 * @author long
 * @Create 2012-10-10 下午3:32:18
 * @QQ 108232706
 * @version 1.0
 * @description RandomUtil
 */
public class RandomUtil {

	private static final Random random = new Random();
	private static final ReentrantLock lock = new ReentrantLock();

	public static int next(int maxValue) {
		lock.lock();
		try {
			return random.nextInt(maxValue);
		} finally {
			lock.unlock();
		}

	}

	public static int next(int minValue, int maxValue)
	{
		if (minValue < maxValue) {
			return random.nextInt(maxValue - minValue) + minValue;
		}
		return minValue;
	}
	public static float next(float minValue, float maxValue)
	{
		if (minValue < maxValue) {
			return random.nextFloat()*(maxValue - minValue) + minValue;
		}
		return minValue;
	}
}
